package CreationPattern.Singleton;

/**
 * @Classname : SingletonClient
 * @Description : 测试 单例性（无论获取多少次对象都是同一个对象）
 * @Author : chentianyu
 * @Date 2022/12/26 23:10
 */


public class SingletonClient {
    public static void main(String[] args) {

        System.out.println("测试 饿汉式");
        Singleton singletonA = Singleton.getInstance();
        Singleton singletonB = Singleton.getInstance();
        Singleton singletonC = Singleton.getInstance();
        System.out.println(singletonA);
        System.out.println(singletonB);
        System.out.println(singletonC);
        System.out.println("--------------------------------------------------------------------");

        System.out.println("测试 懒汉式-方法加锁同步");
        Singleton02 singleton02A = Singleton02.getInstance();
        Singleton02 singleton02B = Singleton02.getInstance();
        Singleton02 singleton02C = Singleton02.getInstance();
        System.out.println(singleton02A);
        System.out.println(singleton02B);
        System.out.println(singleton02C);
        System.out.println("--------------------------------------------------------------------");

        System.out.println("测试 懒汉式-双重检查锁");
        Singleton03 singleton03A = Singleton03.getInstance();
        Singleton03 singleton03B = Singleton03.getInstance();
        Singleton03 singleton03C = Singleton03.getInstance();
        System.out.println(singleton03A);
        System.out.println(singleton03B);
        System.out.println(singleton03C);
        System.out.println("--------------------------------------------------------------------");

        System.out.println("测试 静态内部类");
        Singleton04 singleton04A = Singleton04.getInstance();
        Singleton04 singleton04B = Singleton04.getInstance();
        Singleton04 singleton04C = Singleton04.getInstance();
        System.out.println(singleton04A);
        System.out.println(singleton04B);
        System.out.println(singleton04C);
        System.out.println("--------------------------------------------------------------------");

        System.out.println("测试 枚举式");
        Singleton05 singleton05A = Singleton05.INSTANCE;
        Singleton05 singleton05B = Singleton05.INSTANCE;
        Singleton05 singleton05C = Singleton05.INSTANCE;
        System.out.println(singleton05A);
        System.out.println(singleton05B);
        System.out.println(singleton05C);
        System.out.println(singleton05A == singleton05B);
        System.out.println(singleton05B == singleton05C);
        System.out.println("--------------------------------------------------------------------");

    }
}


/** 2022/12/26
 * 测试 饿汉式
 * CreationPattern.Singleton.CreationPattern.Singleton@75b84c92
 * CreationPattern.Singleton.CreationPattern.Singleton@75b84c92
 * CreationPattern.Singleton.CreationPattern.Singleton@75b84c92
 * --------------------------------------------------------------------
 * 测试 懒汉式-方法加锁同步
 * CreationPattern.Singleton.Singleton02@6bc7c054
 * CreationPattern.Singleton.Singleton02@6bc7c054
 * CreationPattern.Singleton.Singleton02@6bc7c054
 * --------------------------------------------------------------------
 * 测试 懒汉式-双重检查锁
 * CreationPattern.Singleton.Singleton03@232204a1
 * CreationPattern.Singleton.Singleton03@232204a1
 * CreationPattern.Singleton.Singleton03@232204a1
 * --------------------------------------------------------------------
 * 测试 静态内部类
 * CreationPattern.Singleton.Singleton04@4aa298b7
 * CreationPattern.Singleton.Singleton04@4aa298b7
 * CreationPattern.Singleton.Singleton04@4aa298b7
 * --------------------------------------------------------------------
 * 测试 枚举式
 * INSTANCE
 * INSTANCE
 * INSTANCE
 * true
 * true
 * --------------------------------------------------------------------
 */
